//
//  HEEduOperationCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/17.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEEduOperationCell.h"
#import "HEItemBtnView.h"
#import "HEEduVideoModel.h"

@interface HEEduOperationCell ()

@property (nonatomic, strong) HEItemBtnView *photoBtn;
@property (nonatomic, strong) HEItemBtnView *collBtn;

@end

@implementation HEEduOperationCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    HEItemBtnView *photoBtn = [HEItemBtnView new];
    photoBtn.title = @"点赞";
    photoBtn.imageName = @"rating_sel";
    [photoBtn resetLayoutWithWidth:25 height:25];
    KWeakSelf
    photoBtn.selectBlock = ^(HEItemBtnView * _Nonnull btn) {
        if ([weakSelf.delegate respondsToSelector:@selector(cellWithThumbupHandler)]) {
            [weakSelf.delegate cellWithThumbupHandler];
        }
    };
    [self.contentView addSubview: photoBtn];
    _photoBtn = photoBtn;
    
    HEItemBtnView *collBtn = [HEItemBtnView new];
    collBtn.title = @"收藏";
    collBtn.imageName = @"collection_sel";
    [collBtn resetLayoutWithWidth:25 height:25];
    collBtn.selectBlock = ^(HEItemBtnView * _Nonnull btn) {
        if ([weakSelf.delegate respondsToSelector:@selector(cellWithCollectHandler)]) {
            [weakSelf.delegate cellWithCollectHandler];
        }
    };
    [self.contentView addSubview: collBtn];
    _collBtn = collBtn;

    HEItemBtnView *shareBtn = [HEItemBtnView new];
    shareBtn.title = @"分享";
    shareBtn.imageName = @"share_normal";
    [shareBtn resetLayoutWithWidth:25 height:25];
    shareBtn.selectBlock = ^(HEItemBtnView * _Nonnull btn) {
        if ([weakSelf.delegate respondsToSelector:@selector(cellWithShareHandler)]) {
            [weakSelf.delegate cellWithShareHandler];
        }
    };
    [self.contentView addSubview: shareBtn];
 
    NSArray *arr = @[photoBtn, collBtn, shareBtn];
    
    [arr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(5);
//        make.width.offset(40);
//        make.height.offset(50);
        make.bottom.equalTo(self.contentView).offset(-15);
    }];
 
    [arr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:10 tailSpacing:10];
}

- (void)configCellWithModel:(id)model indexPath:(NSIndexPath *)indexPath{
    _delegate = self.proxyVC;
    
    HEEduVideoModel *item = (HEEduVideoModel *)model;

    if ([@"1" isEqualToString:item.video.firstObject.thumbup]) {
        _photoBtn.imageName = @"rating_sel";
    }else {
        _photoBtn.imageName = @"rating_normal";
    }
    
    if (item.collection > 0) {
        _collBtn.imageName = @"collection_sel";
    }else {
        _collBtn.imageName = @"collection_normal";
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
